import { getData } from '@/utils/request'

import type { WarDataType } from './interface'
// import { mapMockData } from "./mockData/mapData"

//  报警最新的top
export interface Top5WarnDataItem {
  alermName: string
  personName: string
  carBrand: string
  alermDate: string
  alerDateText?: string
  alerImg?: string
  alarmGUID: string
}

export const getTop5WarnData = (params: {
  entId: string
  timeType: WarDataType
  topNum: number
}) => {
  // let finallData = Top5WarnMockData
  // const { topNum } = params
  // if (topNum === 1) {
  //   finallData = Top5WarnMockData1
  // } else if (topNum === 2) {
  //   finallData = Top5WarnMockData2
  // } else if (topNum === 3) {
  //   finallData = Top5WarnMockData3
  // }
  // console.log("--topNum--:", topNum)
  // return Promise.resolve({ data: finallData as Top5WarnDataItem[] })

  return getData<{ allSum: number; alermTopList: Top5WarnDataItem[] }>(
    '/code/api/dp2/alermTop',
    params
  )
}

//车辆报警总数
export const getAlarmCarNum = (params: {
  entId: string
  timeType: WarDataType
}) => {
  return getData<{ carSum: number }>('/code/api/dp2/alarmCarNum', params)
}

//10种类型的风险数据
interface TenTypeWarnReqData {
  allSum: number
  alermKvs: TenTypeWarnDataItem[]
}

export interface TenTypeWarnDataItem {
  name: string
  value: number
  piont: number
}

export const getTenTypeWarnData = (params: {
  entId: string
  timeType: WarDataType
}) => {
  // return Promise.resolve({ data: params.testType === 2 ? tenTypeWarnMockData2 : tenTypeWarnMockData })

  return getData<TenTypeWarnReqData>('/code/api/dp2/fxQuery', params)
}

export interface WarnGpsDetail {
  plateNumber: string
  longitude: number
  latitude: number
  lat: number
  lng: number
  addressDict?: {
    //点聚合
    adCode: string
    cityAdcode: string
    cityName: string
    name: string
    provinceCode: string
    provinceName: string
  }
  address?: string
}

//地图数据
export const getMapAlerData = (params: { entId: string }) => {
  // return Promise.resolve({ data: mapMockData as WarnGpsDetail[] })
  return getData<WarnGpsDetail[]>('/code/api/dp2/alermgGps', params)
}

// 报警高风险时段
export const getWarnTimeData = async (params: {
  entId: string
  timeType: string
}) => {
  const { data } = await getData<Array<{ name: string; value: number }>>(
    '/code/api/dp2/fxsd',
    params
  )
  return data
}

export interface WarnClassVO {
  entSum: number
  carSum: number
  personSum: number
  entKvs: string[]
  carKvs: string[]
  personKvs: string[]
}

// 今日风险报警分类
export const getWarnClass = async (params: { entId: string }) => {
  const { data } = await getData<WarnClassVO>('/code/api/dp2/fxg', params)
  return data
}

export type WorkOrderRecord = {
  name: string
  piont: number // 百分比
  value: number
}

type WorkOrderVO = Record<'entKvs' | 'carKvs' | 'personKvs', WorkOrderRecord[]>

// 今日风险报警分类
export const getWorkOrderClass = async (params: { entId: string }) => {
  const { data } = await getData<WorkOrderVO>('/code/api/dp2/gdg', params)
  return data
}
